<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Picture extends Model
{
  /**
   * Insert validation rules.
   *
   * @var array
   */
  public static $insertRules = [
    'user_id' => 'required|int|unique:pictures',
    'type_id' => 'required|int',
    'title' => 'required|max:255',
    'filename' => 'nullable|max:255',
    'original_filename' => 'nullable|max:255',
    'mime_type' => 'nullable|max:255',
    'size' => 'nullable|int',
    'active' => 'nullable|boolean',
    'image' => 'required|image|mimes:png|max:2048',
  ];

  /**
   * Update validation rules.
   *
   * @var array
   */
  public static $updatetRules = [
    'user_id' => 'nullable|int|unique:pictures',
    'type_id' => 'nullable|int',
    'title' => 'nullable|max:255',
    'filename' => 'nullable|max:255',
    'original_filename' => 'nullable|max:255',
    'mime_type' => 'nullable|max:255',
    'size' => 'nullable|int',
    'active' => 'nullable|boolean',
    'image' => 'nullable|image|mimes:png|max:2048',
  ];

  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = [
    'user_id',
    'type_id',
    'title',
    'filename',
    'original_filename',
    'mime_type',
    'size',
    'active',
  ];

  /**
   * The attributes excluded from the model's JSON form.
   *
   * @var array
   */
  protected $hidden = [
    'user_id',
    'type_id',
  ];

  /**
   * The attributes that should be cast to native types.
   *
   * @var array
   */
  protected $casts = [];

  /**
   * Relationship with user.
   */
  public function user()
  {
    return $this->belongsTo(User::class);
  }

  /**
   * Relationship with type.
   */
  public function type()
  {
    return $this->belongsTo(Type::class);
  }
}
